package com.barcamp.bean;

import java.util.ArrayList;
import java.util.List;
import javax.faces.component.UIData;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import com.barcamp.entity.EventType;
import com.barcamp.entity.RegisterData;
import com.barcamp.manager.RegisterManager;
import com.exception.PersistenceException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class BarcampBean extends SqlMapClientDaoSupport{
	private RegisterData registerData = new RegisterData();
	private List<RegisterData> resultList = new ArrayList<RegisterData>();
	private List<RegisterData> presentList = new ArrayList<RegisterData>();
	private List<RegisterData> absenceList = new ArrayList<RegisterData>();
	private EventType eventType = new EventType();
	private UIData uiDataTable; 
	private UIData uiEvent;
	private EventType type;

	
	public EventType getType() {
		return type;
		
	}

	public void setType(EventType type) {
		this.type = type;
	}


	
	public UIData getUiEvent() {
		return uiEvent;
	}

	public void setUiEvent(UIData uiEvent) {
		this.uiEvent = uiEvent;
	}

	public EventType getEventType() {
		return eventType;
	}

	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}
	//private List<EventType> eventlist = new ArrayList<EventType>();
	
//	public List<EventType> getEventlist() {
//		
//		return eventlist;
//	}
//
//	public void setEventlist(List<EventType> eventlist) {
//		this.eventlist = eventlist;
//	}
//	

	public List<RegisterData> getAbsenceList() {
		absenceList = getRegisterManager().findByAbsenceStatus(registerData.getEventId());
		return absenceList;
	}

	public void setAbsenceList(List<RegisterData> absenceList) {
		this.absenceList = absenceList;
	}

	public List<RegisterData> getPresentList() {

		type=(EventType) uiDataTable.getRowData();
		System.out.println("ID"+type.getId());

		//System.out.println(registerData.getEventId());
		presentList = getRegisterManager().findByPresentStatus(registerData.getEventId()); 

		presentList = getRegisterManager().findByPresentStatus(type.getId()); 

		return presentList;
	}

	public void setPresentList(List<RegisterData> presentList) {
		this.presentList = presentList;
	}
	
	public UIData getUiDataTable() {
		return uiDataTable;
	}

	public void setUiDataTable(UIData uiDataTable) {
		this.uiDataTable = uiDataTable;
	}
	
	public List<RegisterData> getResultList() {
		resultList = getRegisterManager().findRegisterData();
		System.out.println(resultList);
		return resultList;
	}

	public void setResultList(List<RegisterData> resultList) {
		this.resultList = resultList;
	}

	public RegisterManager getRegisterManager(){
		RegisterManager registerManager = null;
		XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-beans.xml"));
		registerManager =(RegisterManager)factory.getBean("RegisterManager");
		return registerManager;
	}

	public RegisterData getRegisterData() {
		return registerData;
	}

	public void setRegisterData(RegisterData registerData) {
		this.registerData = registerData;
	}
	
	public String register(){
		getRegisterManager().registerAttendance(registerData);
		return "register";
	}
	public String updateRegister(){
		registerData = (RegisterData)uiDataTable.getRowData();
		registerData.setStatus("presence");
		getRegisterManager().updateRegister(registerData);
		return "update";
	}
	public String findAttendantList(){
		eventType = (EventType)uiEvent.getRowData();
		registerData.setEventId(eventType.getId());
		return "findAttendantList";
	}
	public String findAbsenceList(){
		eventType = (EventType)uiEvent.getRowData();
		registerData.setEventId(eventType.getId());
		return "findAbsenceList";
	}
}
